<?php echo $this->fetch('header.html'); ?>
<?php if ($_GET['type'] != 'iframe'): ?>
<style>
.kdorder_add {background:#e9e9e9;}
.kdorder_add th {font-size:13px; color:#333; background:#f0f7ff; width:150px; font-weight:normal;text-align:right; padding-right:5px;}
.kdorder_add th em {font-style:normal; color:#F00; margin-right:8px}
.kdorder_add td{padding:5px; background:#FFF;}
.kdorder_add td span{color:#F00; margin-left:5px;} 
.inputBorder1{background: #333;width: 360px;color: #fff;padding: 15px;font-size: 30px;}
.inputBorder{border: 1px #CCC solid;height: 20px;line-height: 20px;padding: 4px 8px; width:280px}
.botton_submit {border:0;background:#ed5736;height:31px;width:100px;text-align:center;line-height:31px;font-family:"Microsoft YaHei";font-size:14px;color:#fff;cursor:pointer;border-radius:4px; margin-right:10px}
</style>
<div id="rightTop">
  <ul class="subnav">
    <li><span>扫描打印快递单</span></li>
    <li><a class="btn0" href="index.php?app=kd_order&act=scan_print">打印快递单</a></li>
  </ul>
</div>
<div class="info2">
<form action="" method="post" id="form_box">
<table width="100%" cellspacing="1" class="kdorder_add">
  <tr><td colspan="2" style="padding:12px 8px;background:#ffffe5;line-height:18px; font-size:13px">操作顺序：第一步，请使用带有回车功能的条码枪扫描或录入包裹条形码的运单号，回车。第二步，打印出快递面单
</td></tr>
  <tr>
    <th>操作模式：</th>
    <td><select name="select" id="cangku" class="select_class" onChange="Javascript:location.href='index.php?app=kd_order&act=scan_print&select='+this.options[this.selectedIndex].value">
        <option value="0">单个打印模式</option>
        <option value="1" <?php if ($this->_var['print_select'] == '1'): ?>selected="selected"<?php endif; ?>>批量打印模式</option>
        </select></td>
  </tr>
  <tr>
    <th><em>*</em>包裹运单号：</th>
    <td><?php if ($this->_var['print_select'] == '1'): ?><textarea name="yundanhao" class="inputBorder" id="yundanhao" style="width:380px;height:80px"></textarea><span id="yundanhaotip">回车换行，由于接口限制一次最多只能批量打印50份，请注意</span><?php else: ?><input type="text" name="yundanhao" id="yundanhao" class="inputBorder1" onkeypress="return doClick(event);"/><span id="yundanhaotip">回车</span><?php endif; ?>
    </td>
  </tr>
  <tr>
    <th>&nbsp;</th>
    <td>
      <input type="submit" name="addbtn" class="botton_submit" value="立即打印" onclick="return Check_form();"/>
      <input type="reset" name="resetbtn" class="botton_submit" value="清空内容" style="background:#CCC"/>
      <input type="hidden" name="act"  value="scan_print"/>
      </td>
  </tr>
  <tr><td colspan="2"><iframe id="print_iframe" src="" width="100%" height="800" frameborder="0"></iframe></td></tr>  
  </table>
</form>
</div>
<script type="text/javascript">
$(document).ready(function(){
    $("#yundanhao").focus();
	if( $("#yundanhao").attr("type") == 'text')
	{
	  $("#yundanhao").keyup(function () {
		  if (event.keyCode == 13 && $("input[name='addbtn']").val() == "立即打印" ) {
			  Check_form();
		  }
	  });
	}
});
function Check_form(){
  if ($("#yundanhao").val() == "") {alert("请输入包裹运单号");$("#yundanhao").focus(); return false;}
  var yundanhao = $("#yundanhao").val().replace(/[\r\n]/g,',');
  $("#print_iframe").attr("src", "index.php?app=kd_order&act=scan_print&type=iframe&yundanhao="+yundanhao);
  if( $("#yundanhao").attr("type") == 'text'){ 
     $("#yundanhao").val('').focus();
  }
  $("input[name='addbtn']").attr('disabled',"true");
  $("input[name='addbtn']").css("background-color","#ccc"); 
  $("input[name='addbtn']").val("获取数据..");
  return false;
}
//按enter键,阻止提交订单
function doClick(event){
  var key;
  if (window.event){
	  key = window.event.keyCode; //IE  
  }else{
	  key = event.which; //firefox  
  }
  if (key == 13) {
	  try{
		  if (window.event) {//ie  
			  window.event.keyCode = 0;
			  window.event.returnValue = false;
		  }else {//firefox  
			  return false;
		  }
	  }catch(ex) {}
  }
}
</script>
<?php echo $this->fetch('footer.html'); ?>
<?php else: ?>
<script type="text/javascript" src="<?php echo $this->_var['site_url']; ?>/data/barcode/jquery-barcode.js"></script>
<?php $_from = $this->_var['order_list']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'data_info');$this->_foreach['v'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['v']['total'] > 0):
    foreach ($_from AS $this->_var['data_info']):
        $this->_foreach['v']['iteration']++;
?>
<script type="text/javascript">
$(document).ready(function(){
  $("#print_<?php echo $this->_var['data_info']['order_id']; ?> input[name='datoubi']").val("<?php echo $this->_var['data_info']['datoubi']; ?>");
  $("#print_<?php echo $this->_var['data_info']['order_id']; ?> input[name='txtRece_name']").val("<?php echo $this->_var['data_info']['txtRece_name']; ?>");
  $("#print_<?php echo $this->_var['data_info']['order_id']; ?> input[name='txtRece_mobilephone']").val("<?php echo $this->_var['data_info']['txtRece_mobilephone']; ?>");
  $("#print_<?php echo $this->_var['data_info']['order_id']; ?> textarea[name='txtRece_address']").val("<?php echo $this->_var['data_info']['txtRece_province']; ?><?php echo $this->_var['data_info']['txtRece_city']; ?><?php echo $this->_var['data_info']['txtqu']; ?><?php echo $this->_var['data_info']['txtRece_address']; ?>");
  $("#print_<?php echo $this->_var['data_info']['order_id']; ?> input[name='txt_name']").val("<?php echo $this->_var['data_info']['txt_name']; ?>");
  $("#print_<?php echo $this->_var['data_info']['order_id']; ?> input[name='txt_mobilephone']").val("<?php echo $this->_var['data_info']['txt_mobilephone']; ?>");
  $("#print_<?php echo $this->_var['data_info']['order_id']; ?> textarea[name='txt_address']").val("<?php echo $this->_var['data_info']['txt_province']; ?><?php echo $this->_var['data_info']['txt_city']; ?><?php echo $this->_var['data_info']['txt_address']; ?>");  
  //$("#print_<?php echo $this->_var['data_info']['order_id']; ?> .barcode").attr("src", "/data/barcode/test.php?codebar=BCGcode39&text=<?php echo $this->_var['data_info']['yundanhao']; ?>"); 
  $("#print_<?php echo $this->_var['data_info']['order_id']; ?> .barcodeImg").barcode("<?php echo $this->_var['data_info']['expressNo']; ?>", "code128",{barWidth:2, barHeight:42,showHRI:true});
  $("#print_<?php echo $this->_var['data_info']['order_id']; ?> .barcodeImgs").barcode("<?php echo $this->_var['data_info']['expressNo']; ?>", "code128",{barWidth:1, barHeight:30,showHRI:true});
});
</script>
<div id="print_<?php echo $this->_var['data_info']['order_id']; ?>"><?php require("../data/files/mall/print/zto_miandan.html"); ?></div>
<?php if (! ($this->_foreach['v']['iteration'] == $this->_foreach['v']['total'])): ?><p style='page-break-after:always'/></p><?php endif; ?>
<?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>  
<style type="text/css" media="print"> .NOPRINT{display:none;} </style>   
<div align="center" style="padding:5px;" class="NOPRINT">
<input type=button value="直接打印" onclick="javascript:window.print();" class="NOPRINT">
</div>
<script type="text/javascript">
$(document).ready(function(){
  parent.$("input[name='addbtn']").removeAttr("disabled");
  parent.$("input[name='addbtn']").css("background-color","#ed5736");
  parent.$("input[name='addbtn']").val("立即打印");
  window.print();
});
</script>
<?php endif; ?>